/**
 * 
 */
package com.fangqk.service.impl;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.fangqk.dao.LinkMapper;
import com.fangqk.entity.Link;
import com.fangqk.service.LinkService;

/**
 * @author G-Train
 *
 */
@Service("linkService")
public class LinkServiceImpl implements LinkService {

	@Resource
	LinkMapper linkMapper;

	@Override
	public Link getOneByUserId(Integer userId) {
		return linkMapper.getOneByUserId(userId);
	}

	@Override
	public int saveMyLinks(Integer userId, String links) {
		Link link = linkMapper.getOneByUserId(userId);
		if (null == link) {
			link = new Link();
			link.setLinks(links);
			link.setUserId(userId);
			link.setCreateTime(new Date());
			return linkMapper.insert(link);
		} else {
			link.setUpdateTime(new Date());
			link.setLinks(links);
			return linkMapper.updateByUserId(link);
		}
	}

	@Override
	public int deleteByUserId(Integer userId) {
		return linkMapper.deleteByUserId(userId);
	}
}
